package com.example.Controller;

import com.example.Pojo.Course;
import com.example.Pojo.PageQuery;
import com.example.Pojo.Result;
import com.example.Service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;
    @GetMapping()
    public Result list(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("分页查询所有课程信息");
        PageQuery<Course> coursePage=courseService.list(page, pageSize);
        return Result.success(coursePage);
    }
    @PostMapping()
    public Result addCourse(@RequestBody Course course) {
        log.info("添加课程信息");
        courseService.addCourse(course);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result deleteCourse(@PathVariable Integer id) {
        log.info("删除课程信息");
        courseService.deleteCourse(id);
        return Result.success();
    }
    @PutMapping()
    public Result updateCourse(@RequestBody Course course) {
        log.info("修改课程信息");
        courseService.updateCourse(course);
        return Result.success();
    }
}
